<template>
<div>
    <Input>
        <Button slot="append" icon="ios-search"></Button>
    </Input>

    <Table border :columns="columns7" :data="list"></Table>
    <Page :total="total" show-sizer :page-size-opts=[4,6,8,10] :page-size="pageSize" placement="top" @on-change="OnPageChange" @on-page-size-change="OnPageSizeChange"></Page>
</div>
</template>
<script>
    export default {
        data () {
            return {
                columns7: [
                    {
                        title: '姓名',
                        key: 'name',
                        render: (h, params) => {
                            return h('div', [
                                h('Icon', {
                                    props: {
                                        type: 'person'
                                    }
                                }),
                                h('strong', params.row.name)
                            ]);
                        }
                    },
                    {
                        title: '年龄',
                        key: 'age'
                    },
                    {
                        title: '住址',
                        key: 'address'
                    },
                    {
                        title: '操作',
                        key: 'action',
                        width: 150,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.show(params.index)
                                        }
                                    }
                                }, '修改'),
                                h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    on: {
                                        click: () => {
                                            this.remove(params.index)
                                        }
                                    }
                                }, '删除')
                            ]);
                        }
                    }
                ],
                list: [],
                pageSize:4,
                total:0,
                page:1,
            }
        },
        
        methods: {
            show (index) {
                this.$Modal.info({
                    title: 'User Info',
                    content: `Name：${this.data6[index].name}<br>Age：${this.data6[index].age}<br>Address：${this.data6[index].address}`
                })
            },
            remove (index) {
                this.data6.splice(index, 1);
            },
            getListData(){
                this.axios({
                url:'http://localhost:3000/users/list',
                method:'post',
                data:{
                    rows: this.pageSize,
                    page:this.page,
                    
                }
                }).then(res=>{
                    console.log(res.data);
                    this.list=res.data.docs;
                    this.total=res.data.total;
                    
                })
            },
            OnPageChange(page){
                this.page = page
                this.getListData()
            },
            OnPageSizeChange(pageSize){
                this.pageSize = pageSize,
                this.getListData()
            }
            
        },

        mounted(){
            
            this.getListData()
        }
    }
</script>